package com.flong.selenium;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.Platform;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

@SuppressWarnings("all")
public class JRTTTest1 {

	public static WebDriver driver;

	static {
		System.setProperty("webdriver.ie.driver", "C:/Python27/IEDriverServer.exe");
		// driver = new ChromeDriver();
		DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
		capabilities.setJavascriptEnabled(true);
		capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
		capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT);
		capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
		capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
		capabilities.setCapability("allow-blocked-content", true);
		capabilities.setCapability("allowBlockedContent", true);
		capabilities.setPlatform(org.openqa.selenium.Platform.WIN10);
	  
		driver = new InternetExplorerDriver(capabilities); // 问题3解决方法
		
		driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);// SECONDS是秒的意思
		//String url = "http://www.365yg.com/ch/subv_society/";
		
				
	}

	
	
	 
	public static void main(String[] args) throws IOException, Exception {	
		
		String resultText="";
		
		String url  = "https://www.zhihu.com/lives/791702797958676480/participants";
		//driver.navigate().to(url);
		driver.get(url);
		
		//driver.manage().window().fullscreen();
		if(isAlertPresent()){
			driver.switchTo().alert().accept();
		}
		
		/*	
		for(String winHandle : driver.getWindowHandles()){
		    driver.switchTo().window(winHandle);
		    
		}*/
		driver.switchTo().defaultContent();
		
		
		
		Thread.sleep(1800);
		/*JavascriptExecutor js = (JavascriptExecutor)driver;
		js.executeScript("scrollTo(0,10000)");//向下拉到底
		js.executeScript("window.scrollBy(0,3500)");*/
		//WebElement html = driver.findElement(By.cssSelector("div[class='wcommonFeed']"));
		WebElement findElement = driver.findElement(By.tagName("html"));
		System.out.println(findElement.getText());
		
		System.out.println("success");
		driver.close();
		driver.quit();
	}

	protected static boolean isAlertPresent() {
        try {
          driver.switchTo().alert();
          return true;
        } catch (NoAlertPresentException e) {
          return false;
        }
      }
}